<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: SXLWTT
  Date: 2021/11/2
  Time: 11:26
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <script src="/js/jquery-1.9.1.min.js"></script>
    <script src="/js/fileupload.js"></script>
    <link rel="stylesheet" href="/bootstrap-4.6.0-dist/css/bootstrap.min.css">
</head>
<body>
欢迎${user.uname}登录
<form action="/list.do" method="post">
    <input type="hidden" name="pageNum">
    名称：<input type="text" name="cname" value="${map.cname}">
    时间区间：<input type="text" name="opentimeX" value="${map.opentimeX}">
              <input type="text" name="opentimeD" value="${map.opentimeD}">
    省：<select name="sheng">
    <option value="">请选择</option>
        </select>
    市：<select name="shi">
    <option value="">请选择</option>
</select>
    县：<select name="xian">
    <option value="">请选择</option>
</select>
    <input type="submit" value="查询"><a href="/list.do">刷新</a>
</form>
<table class="table table-hover">
    <tr>
        <td>
            <input type="checkbox" name="one">
        </td>
        <td>编号</td>
        <td>名称</td>
        <td>时间</td>
        <td>状态</td>
        <td>图片</td>
        <td>地址</td>
        <td>食品名称</td>
        <td>操作</td>
    </tr>
    <c:forEach items="${pageInfo.list}" var="li">
        <tr>
            <td>
                <input type="checkbox" name="two" value="${li.cid}">
            </td>
            <td>${li.cid}</td>
            <td>${li.cname}</td>
            <td>${li.opentime}</td>
            <td>${li.flag}</td>
            <td><img src="${li.pic}" width="80px"></td>
            <td>${li.shengname}-${li.shiname}-${li.xianname}</td>
            <td>${li.fnames}</td>
            <td>
                <input type="button" value="修改" onclick="update(${li.cid})">
                <input type="button" value="删除" onclick="dell(${li.cid})">
            </td>
        </tr>
    </c:forEach>
    <tr>
        <td colspan="12">
            <%--<a href="javaScript:qwe(1)">首页</a>
            <a href="javaScript:qwe(${pageInfo.isFirstPage?1:pageInfo.prePage})">上一页</a>
            <c:forEach items="${pageInfo.navigatepageNums}" var="index">
                <a href="javaScript:qwe(${index})">${index}</a>
            </c:forEach>
            <a href="javaScript:qwe(${pageInfo.isLastPage?pageInfo.pages:pageInfo.nextPage})">下一页</a>
            <a href="javaScript:qwe(${pageInfo.pages})">尾页</a>--%>
            <nav aria-label="Page navigation example">
                <ul class="pagination">
                    <li class="page-item"><a class="page-link" href="javaScript:qwe(1)">首页</a></li>
                    <li class="page-item"><a class="page-link" href="javaScript:qwe(${pageInfo.isFirstPage?1:pageInfo.prePage})">上一页</a></li>
                    <c:forEach items="${pageInfo.navigatepageNums}" var="index">

                        <li class="page-item ${pageInfo.pageNum==index?'active':''}"><a class="page-link" href="javaScript:qwe(${index})">${index}</a></li>
                    </c:forEach>
                    <li class="page-item"><a class="page-link" href="javaScript:qwe(${pageInfo.isLastPage?pageInfo.pages:pageInfo.nextPage})">下一页</a></li>
                    <li class="page-item"><a class="page-link" href="javaScript:qwe(${pageInfo.pages})">尾页</a></li>

                </ul>
            </nav>
            <input type="button" value="添加" onclick="add()">
            <input type="button" value="批量删除" onclick="delAll()">
        </td>
    </tr>
</table>
</body>
</html>
<script>
    function update(cid){
        location="toupdate.do?cid="+cid;
    }
    $("[name='one']").change(function () {
        $("[name='two']").prop("checked",$(this).prop("checked"))
    })
    function delAll() {
        var aa=$("[name='two']:checked").map(function () {
            return $(this).val()
        }).get().toString()
        alert(aa)
        $.ajax({
            url:"dels.do",
            data:{"cid":aa},
            type:"post",
            dataType:"json",
            success:function (obj) {
                if (obj>0){
                    alert("删除成功")
                    location="list.do"
                }
            }

        })
    }
    function dell(cid) {
        $.ajax({
            url:"del.do",
            data:{cid:cid},
            type:"post",
            dataType:"json",
            success:function (obj) {
                if (obj>0){
                    alert("删除成功")
                    location="list.do"
                }
            }

        })
    }
    function add() {
        location="toadd.do"
    }
    function qwe(pageNum) {
        $("[name='pageNum']").val(pageNum)
        $("form").submit()
    }
    //三级联动
    $(function () {
        $.ajax({
            url:"listCity.do",
            data:{pid:0},
            type:"post",
            dataType:"json",
            success:function (obj) {
                for (var i in obj){
                    if ("${map.sheng}"==obj[i].id){
                        $("[name='sheng']").append("<option selected value='"+obj[i].id+"'>"+obj[i].name+"</option>")
                        $("[name='sheng']").trigger("change")
                    }else {
                        $("[name='sheng']").append("<option value='"+obj[i].id+"'>"+obj[i].name+"</option>")
                        $("[name='sheng']").trigger("change")
                    }

                }
            }
        })

        $("[name='sheng']").change(function () {
            $("[name='shi']").empty()
            $("[name='xian']").empty()
            var aaa= $("[name='sheng']").val()
            $.ajax({
                url:"listCity.do",
                data:{pid:aaa},
                type:"post",
                dataType:"json",
                success:function (obj) {
                    for (var i in obj){
                        $("[name='shi']").append("<option value='"+obj[i].id+"'>"+obj[i].name+"</option>")
                        $("[name='shi']").trigger("change")
                    }
                }
            })
        })
        $("[name='shi']").change(function () {
            $("[name='xian']").empty()
            var aaa= $("[name='shi']").val()
            $.ajax({
                url:"listCity.do",
                data:{pid:aaa},
                type:"post",
                dataType:"json",
                success:function (obj) {
                    for (var i in obj){
                        $("[name='xian']").append("<option value='"+obj[i].id+"'>"+obj[i].name+"</option>")
                    }
                }
            })
        })
    })
</script>